package com.crazymakercircle.util;


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.Properties;


/**
 * @author
 */
public class ConfigProperties {

    private String properiesName = "";
    private Properties properties = new Properties();


    public ConfigProperties() {

    }

    public ConfigProperties(String fileName) {
        this.properiesName = fileName;
    }


    protected void loadFromFile() {
        try (InputStreamReader ireader = new InputStreamReader(new FileInputStream(IOUtil.getResourcePath(properiesName)), "utf-8");) {
            //解决读非UTF-8编码的配置文件时，出现的中文乱码问题
            properties.load(ireader);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 按key获取值
     *
     * @param key
     * @return
     */
    public String readProperty(String key) {
        String value = "";
        value = properties.getProperty(key);
        return value;
    }


    public String getValue(String key) {
        return readProperty(key);
    }

    public int getIntValue(String key) {
        return Integer.parseInt((readProperty(key)));
    }

    public static ConfigProperties loadFromFile(Class aClass) {
        return null;
    }

    public static void loadAnnotations(Class clazz) {
        ConfigProperties configProperties;
        configProperties = loadFromFile(clazz);
        if (null == configProperties) {
            return;
        }
        Field[] fields = clazz.getDeclaredFields();
    }


}